#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>

#define LOG_NORMAL "logNormal.txt"
#define LOG_ERROR "logError.txt"

int main()
{
    close(1);//关闭标准输出-stdout
    open(LOG_NORMAL, O_WRONLY | O_CREAT | O_APPEND, 0666);//这个时候1号文件描述符对应的是logNormal.txt文件
    //所以原来应该输出到stdout显示器的文件，会被输到logNormal.txt文件中
    
    close(2);//关闭标准错误-stderr 
    open(LOG_ERROR, O_WRONLY | O_CREAT | O_APPEND, 0666);

    printf("hello printf->stdout\n");
    printf("hello printf->stdout\n");
    printf("hello printf->stdout\n");
    printf("hello printf->stdout\n");
    printf("hello printf->stdout\n");

    fprintf(stdout,"hello fprintf->stdout\n");
    fprintf(stdout,"hello fprintf->stdout\n");
    fprintf(stdout,"hello fprintf->stdout\n");
    fprintf(stderr,"hello fprintf->stderr\n");
    fprintf(stdout,"hello fprintf->stdout\n");
    fprintf(stdout,"hello fprintf->stdout\n");

    return 0;
}

